package com.surfacing.rcp.server.listener;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import com.surfacing.rcp.db.dao.StatDoctorDAO;
import com.surfacing.rcp.db.dao.factory.DaoFactory;
import com.surfacing.rcp.model.QueryFilter;
import com.surfacing.rcp.model.common.AbstractMessage;
import com.surfacing.rcp.model.entity.DAOException;
import com.surfacing.rcp.model.entity.StatDoctor;

/**
 * This class will be notified uppon Anforderung changes
 * 
 */
public class StatDoctorListener extends ServerListenerAdapter {

	private static final Logger logger = Logger
			.getLogger(StatDoctorListener.class);
	private final StatDoctorDAO staffDao = DaoFactory.MYSQL
			.createStatDoctorDAO();

	@Override
	public AbstractMessage handleAddRequest(AbstractMessage addObject)
			throws DAOException, SQLException {
		return null;
	}

	/**
	 * Update of a Anforderung
	 */
	@Override
	public AbstractMessage handleUpdateRequest(AbstractMessage updateObject)
			throws DAOException, SQLException {
		return null;
	}

	/**
	 * Listing of all members
	 */
	@Override
	public ArrayList<AbstractMessage> handleListingRequest(
			QueryFilter queryFilter) throws DAOException, SQLException {
		ArrayList<AbstractMessage> list = new ArrayList<AbstractMessage>();
		List<StatDoctor> memberList = null;
		// if there is no filter -> request all
		// if (queryFilter == null || queryFilter.getFilterList().isEmpty()) {
		// log.error("No Filter was provided");
		// // throw new DAOException("StatisticsListener",
		// // "No Filter was provided");
		// } else if
		// (queryFilter.containsFilterType(IFilterTypes.STAT_START_DATE)
		// && queryFilter.containsFilterType(IFilterTypes.STAT_END_DATE)) {
		// // get the query filter
		// SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		//
		// Date startDateTmp = new Date();
		// Date endDateTmp = new Date();
		// try {
		// startDateTmp = format.parse(queryFilter
		// .getFilterValue(IFilterTypes.STAT_START_DATE));
		// endDateTmp = format.parse(queryFilter
		// .getFilterValue(IFilterTypes.STAT_END_DATE));
		// } catch (ParseException e) {
		// log.error("Error while parsing Date.", e);
		// }
		//
		// java.sql.Date start = new java.sql.Date(startDateTmp.getTime());
		// java.sql.Date end = new java.sql.Date(endDateTmp.getTime());

		// memberList = staffDao.getAllStatistics(start, end);
		memberList = staffDao.getAllStatistics();
		if (memberList == null)
			throw new DAOException("StatisticsListener",
					"Failed to get Statistics.");

		list.addAll(memberList);
		// }
		return list;
	}
}